#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll a[200100];
ll f[2010][2][2010];
int main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int T;
    cin>>T;
    while (T--)
    {
        int n;
        cin>>n;
        for (int i=1;i<=n;i++)
            cin>>a[i];
        memset(f,0,sizeof f);
        for (int i=1;i<=n;i++)
        {
            //paint i red
            for (int j=0;j<i;j++)
            {
                f[i][0][j]=max(f[i][0][j],f[i-1][0][j]+(a[i-1]==a[i]?a[i]:0));
                f[i][0][i-1]=max(f[i][0][i-1],f[i-1][1][j]+(a[j]==a[i]?a[i]:0));
            }
            //paint i blue
            for (int j=0;j<i;j++)
            {
                f[i][1][j]=max(f[i][1][j],f[i-1][1][j]+(a[i-1]==a[i]?a[i]:0));
                f[i][1][i-1]=max(f[i][1][i-1],f[i-1][0][j]+(a[j]==a[i]?a[i]:0));
            }
        }
        ll ans=0;
        for (int i=0;i<n;i++)
            ans=max(ans,max(f[n][0][i],f[n][1][i]));
        cout<<ans<<endl;
    }
    return 0;
}